# exerc1.py

def save_text_to_file():
    # 从键盘获取用户输入
    user_input = input("请输入一段文字：")

    # 指定文件路径
    file_path = r"D:\hello.txt"

    try:
        # 打开文件并写入用户输入的文字
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(user_input)
        print(f"文字已成功保存到 {file_path}")
    except IOError as e:
        print(f"保存文件时出错: {e}")


# 调用函数执行任务
if __name__ == "__main__":
    save_text_to_file()